<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of welcome
 *
 * @author Obi
 */
class Admin_kota extends MY_Controller {

    function __construct() {
        parent::__construct();




        $this->mkota = new M_kota();
        $this->mprovinsi = new M_provinsi();
    }

    function index() {

        $data['title'] = 'Daftar Kota';
        $data['list'] = $this->mkota->select_data();

        $data['isi'] = 'isi';
        $this->load->view('template_admin', $data);
    }

    function tambah() {

        $data['title'] = 'Tambah Data Kota';

        $data['provinsi'] = $this->mprovinsi->where("status = '1'")->get();

        $data['id'] = "";
        $data['nama_kota'] = "";
        $data['status'] = "1";
        $data['id_provinsi'] = "";

        $data['isi'] = 'form';
        $this->load->view('template_admin', $data);
    }

    function edit($id = NULL) {

        $data['title'] = 'Ubah Data Kota';

        $dt = $this->mkota->where("id = '$id'")->get();

        $data['provinsi'] = $this->mprovinsi->where("status = '1'")->get();

        $data['id'] = $dt->id;
        $data['nama_kota'] = $dt->nama_kota;
        $data['status'] = $dt->status;
        $data['id_provinsi'] = $dt->id_provinsi;

        $data['isi'] = 'form';
        $this->load->view('template_admin', $data);
    }

    function delete($id) {
        $this->mkota->delete($id);
        redirect("admin_kota");
    }

    function simpan() {
        $id = $this->input->post('id');

        $data = array(
            'nama_kota' => $this->input->post('nama_kota'),
            'status' => $this->input->post('status'),
            'id_provinsi' => $this->input->post('id_provinsi'),
        );

        if ($id == "") {
            $this->mkota->insert($data);
        } else {
            $this->mkota->update($data, $id);
        }

        redirect("admin_kota");
    }

    function data_kota($id_prov = NULL, $id_kota=NULL) {

        echo "<option value=''>Pilih Kota :</option> ";

        if (data_kota != "") {
            $list = $this->mkota->search_data($id_prov);
            foreach ($list as $dta) {
                if($id_kota==$dta->id)
                    $sel="selected";
                else
                    $sel="";
                echo "<option value='$dta->id' $sel>$dta->nama_kota</option> ";
            }
        }
    }

}

?>
